﻿<?php

// Martin Laas - kursus1109

if(!$_POST['act'])
	{
	echo '
	<form method="post" action="'.$_SERVER['PHP_SELF'].'">
	<input type="text" name="nr1" size="5"> 
	<select name="act">
	<option value="add">[ + ]</option>
	<option value="sub">[ - ]</option>
	<option value="div">[ / ]</option>
	<option value="mul">[ * ]</option>
	</select>
	<input type="text" name="nr2" size="5"> 
	<input type="submit" name="doit" value="Arvuta">
	</form>
	';
	}
else{
	if($_POST['act'] == 'add')
	{
	$calc = ($_POST['nr1']+$_POST['nr2']);
	$op = '+';
	}
	if($_POST['act'] == 'sub')
	{
	$calc = ($_POST['nr1']-$_POST['nr2']);
	$op = '-';
	}
	if($_POST['act'] == 'div')
	{
	$calc = ($_POST['nr1']/$_POST['nr2']);
	$op = '/';
	}
	if($_POST['act'] == 'mul')
	{
	$calc = ($_POST['nr1']*$_POST['nr2']);
	$op = '*';
	}
	echo 'Vastus: ',$_POST['nr1'].' '.$op.' '.$_POST['nr2'].' = '.$calc,
	'</br></br>Uus tehe:</br>
	<form method="post" action="'.$_SERVER['PHP_SELF'].'">
	<input type="text" name="nr1" size="5"> 
	<select name="act">
	<option value="add">[ + ]</option>
	<option value="sub">[ - ]</option>
	<option value="div">[ / ]</option>
	<option value="mul">[ * ]</option>
	</select>
	<input type="text" name="nr2" size="5"> 
	<input type="submit" name="doit" value="Arvuta">
	</form>
	';;
	
	}
?>